package gg.server;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


public final class EntityMF {
	private static EntityManagerFactory emfInstance;;

	private EntityMF() {
	}

	public static EntityManagerFactory get() {
		try {			
			if (emfInstance == null)
				emfInstance = Persistence.createEntityManagerFactory("GaeJpa");
			if (emfInstance == null)
				throw new Exception(" EntityManagerFactory init failed ");
		} catch (Exception ex) {
			System.out.println("get EntityManagerFactory failed : "
					+ ex.getMessage());
			ex.printStackTrace();

		}
		return emfInstance;
	}
	
	/**
	 * create a EntityManager for JPA
	 * @return
	 */
	public static EntityManager createEntityManger(){
		return get().createEntityManager();
	}
}
